package com.lzc.springPart.aop.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxyDemo {

    interface Foo{
        void foo() throws NoSuchMethodException;
    }

    static class FooImpl implements Foo{

        @Override
        public void foo() {
            System.out.println("fooImpl");
        }
    }


    public static void main(String[] args) throws NoSuchMethodException {
       /* FooImpl f = new FooImpl();
        Object o = Proxy.newProxyInstance(Foo.class.getClassLoader(),
                new Class[]{Foo.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println(1);
                        Object invoke = method.invoke(f, args);
                        return invoke;
                    }
                });

        Foo foo = (Foo) o;
        foo.foo();*/
        FooImpl f = new FooImpl();
        Foo $JdkProxyFoo = new $JdkProxyFoo((o,m,a)->{
            System.out.println("hello");
            return m.invoke(f,a);
        });
        $JdkProxyFoo.foo();


    }
}
